package cn.doit.tools

import cn.doit.config.JedisConfig
import org.apache.commons.lang.StringUtils
import org.apache.spark.{SparkConf, SparkContext}

/**
  * Created by ZHAOXUHUA 
  * .           on 2018/12/1.
  */
object Appdict2Redis {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
      .setMaster("local[*]")
      .setAppName(this.getClass.getSimpleName)
    val sc = new SparkContext(conf)
    sc.textFile("D:/学习专用/项目/项目四资料/DAY11/app_dict.txt")
      .map(line => line.split("\t", -1))
      .foreachPartition(partition => {
        val jedis = JedisConfig.apply("cls01")
        // 写入数据
        partition.foreach(arr => {
          // appid 和 appname都不能为空，否则没有意义
          if (StringUtils.isNotEmpty(arr(4)) && StringUtils.isNotEmpty(arr(1))) {
            jedis.hset("appdict", arr(4), arr(1))
          }
        })
        jedis.close()
      })
    sc.stop()
  }
}
